clear
cd "~/Dropbox/Life cycle paper/JOP submission/Replication files/YPSP/"


*YPSP FIGURE 3 (LEFT PANEL)
*1973-1982 - parents*
use "parent data.dta"


local demo_controls p_ne73 p_mid73 p_south73 p_west73 p_male i.p_relig65 p_educave65 p_married73 p_somecoll73 p_coll73 i.p_inc73
local attitude_controls p_supportnam p_marijuana p_women p_econlib p_aid p_busing

foreach j of numlist 82{
foreach i in p_church{
preserve
xi: reg `i'`j' i.p_pid373 i.`i'73 `demo_controls' `attitude_controls', cl(psu)
		mat B = r(table)
		gen y= .
		gen se= .
		replace y = B[1,2] 
		replace se = B[2,2] 
collapse y se, by(X)
save "/Users/michelemargolis/Desktop/ypsp results/`i'`j'.dta", replace
restore
}
}


*1965-1973 - students*
clear
cd "~/Dropbox/Life cycle paper/JOP submission/Replication files/YPSP/"

clear
use "student data.dta"
set more off

replace church473=church473/3

local demo_controls ne65 south65 west65 male black colprep65 i.inc73 attend73 children73 married73 nam73
local background_controls i.relig65 i.lit65 closewrents65 p_churchave65 fa_pid65 mo_pid65 p_educave65 p_incave65

foreach j of numlist 73{
foreach i in church4{
preserve
xi: reg `i'`j' i.pid365 i.`i'65 `demo_controls' `background_controls', cl(psu)
		mat B = r(table)
		gen y= .
		gen se= .
		replace y = B[1,2] 
		replace se = B[2,2] 
collapse y se, by(X)
save "/Users/michelemargolis/Desktop/ypsp results/`i'`j'.dta", replace
restore
}
}


*1973-1982; 1973-1997 - students*
replace church82=church82/4
replace church97=church97/4

local demo_controls ne73 south73 west73 male black colprep65 i.inc73 attend73 children73 married73 closewrents73 nam73
local background_controls i.relig65 i.church465 i.lit65 closewrents65 p_churchave65 fa_pid65 mo_pid65 p_educave65 p_incave65
local attitude_controls supportnam women marijuana econlib busing aid
  
foreach j of numlist 82 97{
foreach i in church{
preserve
 xi: reg `i'`j' i.pid373 i.`i'73 `demo_controls' `background_controls' `attitude_controls', cl(psu)
		mat B = r(table)
		gen y= .
		gen se= .
		replace y = B[1,2] 
		replace se = B[2,2] 
	    test _Ipid373_3= _Ipid373_2
collapse y* se*, by(X)
save "/Users/michelemargolis/Desktop/ypsp results/`i'`j'.dta", replace
restore
}
}

clear 
use "/Users/michelemargolis/Desktop/ypsp results/p_church82.dta"
append using "/Users/michelemargolis/Desktop/ypsp results/church97.dta"
append using "/Users/michelemargolis/Desktop/ypsp results/church82.dta"
append using "/Users/michelemargolis/Desktop/ypsp results/church473.dta"


g dv = _n

g lb=y-(1.64*se)
g ub=y+(1.64*se)

gr tw (scatter dv y if dv==1 | dv==2 | dv==3 | dv==4 , col(black) msymbol(circle)) (rcap lb ub dv if dv==1 | dv==2 | dv==3 | dv==4, hor col(black) lpattern(dash) lwidth(medthick)) ///
 (pcarrowi 0.15 0.05 0.15 0.25) (pcarrowi 0.15 -0.05 0.15 -0.25),  ///
ylabel(none) xlabel(none) title() legend(off) ///
xlabel(-0.3(0.10)0.3, nogrid labsize(medium)) scheme(lean1) ///
xscale(range(-0.25, 0.25)) yscale(range(0, 4.5)) ///
ytitle("") xline(0, lpattern(dot) lcol(gs6) lwidth(thick)) ///
 text(1 -0.2 "Parent cohort: 1973-1982", size(medium)) text(2 -0.2 "Student cohort 1973-1997", size(medium)) text(3 -0.2 "Student cohort: 1973-1982", size(medium))  text(4 -0.2 "Student cohort: 1965-1973", size(medium))  ///
text(0.35 -0.15 "Less religious", size(medium))  text(0.35 0.15 "More religious", size(medium)) ///
xtitle("Republican church attendance change relative to Democrats", size(medium)) 



*****RELIGION ON POLITICS
*YPSP FIGURE 3 (RIGHT PANEL)
clear
cd "~/Dropbox/Life cycle paper/JOP submission/Replication files/YPSP/"
use "student data.dta"
set more off

replace pid82=(pid82-1)/6
replace pid73=(pid73-1)/6

local demo_controls ne73 south73 west73 male black colprep65 i.inc73 attend73 children73 married73 closewrents73 nam73
local background_controls i.relig65 i.church465 i.lit65 closewrents65 p_churchave65 fa_pid65 mo_pid65 p_educave65 p_incave65
local attitude_controls supportnam women marijuana econlib busing aid

foreach j of numlist 1 2 3 4{
local demo_controls ne73 south73 west73 male black colprep65 i.inc73 attend73 children73 married73 closewrents73 nam73
local background_controls i.relig65 i.church465 i.lit65 closewrents65 p_churchave65 fa_pid65 mo_pid65 p_educave65 p_incave65
local attitude_controls supportnam women marijuana econlib busing aid

xi: reg pid82 i.church73 i.pid73 `demo_controls' `background_controls' `attitude_controls', cl(psu)
		preserve
		mat B = r(table)
		gen church_y = .
		gen church_se = .	
		replace church_y = B[1,`j'] 
		replace church_se = B[2,`j'] 
collapse church_y* church_se*, by(X)
g pid=1
save "/Users/michelemargolis/Desktop/temp/church_pid_`j'.dta", replace
restore
}


foreach j of numlist 1 2 3 4{
local demo_controls ne73 south73 west73 male black colprep65 i.inc73 attend73 children73 married73 closewrents73 nam73
local background_controls i.relig65 i.church465 i.lit65 closewrents65 p_churchave65 fa_pid65 mo_pid65 p_educave65 p_incave65
local attitude_controls supportnam women marijuana econlib busing aid

xi: reg repvote82 i.church73 repvote73 pid73 `demo_controls' `background_controls' `attitude_controls', cl(psu)
		preserve
		mat B = r(table)
		gen church_y = .
		gen church_se = .	
		replace church_y = B[1,`j'] 
		replace church_se = B[2,`j'] 
collapse church_y* church_se*, by(X)
g vote=1
save "/Users/michelemargolis/Desktop/temp/church_vote_`j'.dta", replace
restore
}


clear
use "/Users/michelemargolis/Desktop/temp/church_vote_1.dta"
append using "/Users/michelemargolis/Desktop/temp/church_vote_2.dta"
append using "/Users/michelemargolis/Desktop/temp/church_vote_3.dta"
append using "/Users/michelemargolis/Desktop/temp/church_vote_4.dta"
append using "/Users/michelemargolis/Desktop/temp/church_pid_1.dta"
append using "/Users/michelemargolis/Desktop/temp/church_pid_2.dta"
append using "/Users/michelemargolis/Desktop/temp/church_pid_3.dta"
append using "/Users/michelemargolis/Desktop/temp/church_pid_4.dta"
cd "~/Dropbox/Life cycle paper/JOP submission/"

g dv= _n
recode dv (5=6) (6=7) (7=8) (8=9)

g lb_church= church_y - (1.64*church_se)
g ub_church= church_y + (1.64*church_se)

gr tw (scatter dv church_y if dv<=4, col(gs10) msymbol(square)) (rcap lb_church ub_church dv if dv<=4, hor col(gs10) lpattern(solid) lwidth(medthick)) ///
(scatter dv church_y if dv>=6, col(black) msymbol(circle)) (rcap lb_church ub_church dv if dv>=6, hor col(black) lpattern(dash) lwidth(medthick)) ///
(pcarrowi -0.9 0.05 -0.9 0.25) (pcarrowi -0.9 -0.05 -0.9 -0.25), ///
ylabel(none) xlabel(none, labsize(medium)) title() legend(off) ///
xlabel(-0.3(0.10)0.3, nogrid) scheme(lean1) ///
xscale(range(-0.3, 0.3)) yscale(range(-1.25, 10)) ///
ytitle("") xline(0, lpattern(dot) lcol(gs6) lwidth(thick)) ///
text(9 -0.2 "A few times per year", size(medium)) text(8 -0.2 "Once or twice a month", size(medium)) text(7 -0.2 "Almost every week", size(medium)) text(6 -0.2 "Every week", size(medium)) ///
text(7.5 0.23 "Party identification", size(medium))  text(2.65 0.25 "Vote choice", size(medium)) text(-0.5 -0.15 "More Democratic", size(medium))  text(-0.5 0.15 "More Republican", size(medium)) ///
xtitle("Political change relative to church non-attenders, 1973 to 1982", size(medium)) 







 



